<?php

/**
 * This is the model class for table "author".
 *
 * The followings are the available columns in table 'author':
 * @property integer $id_author
 * @property string $fullname
 * @property string $nickname
 * @property string $birthday
 * @property string $death
 * @property string $birthplace
 * @property string $biography
 * @property string $homepage
 * @property string $avatar
 * @property integer $id_user
 * @property string $date_add
 * @property string $date_modified
 *
 * The followings are the available model relations:
 * @property Book[] $books
 * @property AuthorComment[] $authorComments
 * @property Me[] $mes
 * @property Poem[] $poems
 */
class Author extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Author the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'author';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id_author, fullname', 'required'),
			array('id_author, id_user', 'numerical', 'integerOnly'=>true),
			array('fullname, nickname, birthplace, homepage, avatar', 'length', 'max'=>255),
			array('birthday, death, biography, date_add, date_modified', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id_author, fullname, nickname, birthday, death, birthplace, biography, homepage, avatar, id_user, date_add, date_modified', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'books' => array(self::MANY_MANY, 'Book', 'author_book(id_author, id_book)'),
			'authorComments' => array(self::HAS_MANY, 'AuthorComment', 'id_author'),
			'mes' => array(self::MANY_MANY, 'Me', 'author_fan(id_author, id_me)'),
			'poems' => array(self::HAS_MANY, 'Poem', 'id_author'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_author' => 'Id Author',
			'fullname' => 'Fullname',
			'nickname' => 'Nickname',
			'birthday' => 'Birthday',
			'death' => 'Death',
			'birthplace' => 'Birthplace',
			'biography' => 'Biography',
			'homepage' => 'Homepage',
			'avatar' => 'Avatar',
			'id_user' => 'Id User',
			'date_add' => 'Date Add',
			'date_modified' => 'Date Modified',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id_author',$this->id_author);
		$criteria->compare('fullname',$this->fullname,true);
		$criteria->compare('nickname',$this->nickname,true);
		$criteria->compare('birthday',$this->birthday,true);
		$criteria->compare('death',$this->death,true);
		$criteria->compare('birthplace',$this->birthplace,true);
		$criteria->compare('biography',$this->biography,true);
		$criteria->compare('homepage',$this->homepage,true);
		$criteria->compare('avatar',$this->avatar,true);
		$criteria->compare('id_user',$this->id_user);
		$criteria->compare('date_add',$this->date_add,true);
		$criteria->compare('date_modified',$this->date_modified,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}